﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MadLibrary.Text;

namespace MadLibrary.Managing.Users
{
    /// <summary>
    /// Serves as simple user property holder.
    /// </summary>
    public class StandartUser : User
    {
        /// <summary>
        /// Gets or sets users' describtion.
        /// </summary>
        public string Description { get; set; }
        /// <summary>
        /// Gets of sets users' registration date.
        /// </summary>
        public DateTime? RegisterDate { get; set; }
        /// <summary>
        /// Gets or sets last users' login date.
        /// </summary>
        public DateTime? LastLoginDate { get; set; }
        /// <summary>
        /// Gets or sets users' age.
        /// </summary>
        public byte ?Age { get; set; }
        /// <summary>
        /// Sets default values of properties.
        /// </summary>
        private void SetDefault()
        {
            this.Description = "";
            this.RegisterDate = null;
            this.LastLoginDate = null;
            this.Age = null;
        }
        /// <summary>
        /// Creating new StandartUser object instance with default values.
        /// </summary>
        public StandartUser()
            : base()
        {
            this.SetDefault();
        }
        /// <summary>
        /// Creates new StandartUser object instance with specified username.
        /// </summary>
        /// <param name="Username">Specifies users' username.</param>
        public StandartUser(string Username)
            : base(Username)
        {
            this.SetDefault();
        }
        /// <summary>
        /// Creates new StandartUser object instance with specified username and password.
        /// </summary>
        /// <param name="Username">Specifies users' username.</param>
        /// <param name="Password">Specifies users' password.</param>
        public StandartUser(string Username, string Password)
            : base(Username, Password)
        {
            this.SetDefault();
        }
        /// <summary>
        /// Creates new StandartUser object instance with specified key data.
        /// </summary>
        /// <param name="Username">Specifies users' username.</param>
        /// <param name="Password">Specifies users' password.</param>
        /// <param name="Email">Specifies users' email.</param>
        public StandartUser(string Username, string Password, string Email)
            : base(Username, Password, Email)
        {
            this.SetDefault();
        }
        /// <summary>
        /// Creates new StandartUser object instance with specified username and random password.
        /// </summary>
        /// <param name="Username">Specifies users' username.</param>
        /// <param name="rtpass">Specifies password generator of user.</param>
        public StandartUser(string Username, RandomText rtpass)
            : base(Username, rtpass)
        {
            this.SetDefault();
        }
        /// <summary>
        /// Creates new StandartUser object instance with specified username and email and with random password.
        /// </summary>
        /// <param name="Username">Specifies users' username.</param>
        /// <param name="rtpass">Specifies password generator of user.</param>
        /// <param name="Email">Specifies users' email.</param>
        public StandartUser(string Username, RandomText rtpass, string Email)
            : base(Username, rtpass, Email)
        {
            this.SetDefault();
        }
        /// <summary>
        /// Creates new StandartUser object instance and sets all properties to specified values.
        /// </summary>
        /// <param name="Username">Specifies users' username.</param>
        /// <param name="Password">Specifies users' password.</param>
        /// <param name="Email">Specifies users' email.</param>
        /// <param name="Description">Specifies users' describtion.</param>
        /// <param name="RegisterDate">Specifies users' registration date.</param>
        /// <param name="LastLoginDate">Specifies users' last login date.</param>
        /// <param name="Age">Specifies users' age.</param>
        public StandartUser(string Username, string Password, string Email, string Description,
            DateTime RegisterDate, DateTime LastLoginDate, byte Age)
            : base(Username, Password, Email)
        {
            this.SetDefault();
            this.Description = Description;
            this.RegisterDate = RegisterDate;
            this.LastLoginDate = LastLoginDate;
            this.Age = Age;
        }
        /// <summary>
        /// Compares two users.
        /// </summary>
        /// <param name="usr">Specifies user for comparasion.</param>
        /// <returns>True when success, False when fail.</returns>
        public override bool CompareUsers(User usr)
        {
            if (usr.UserName == this.UserName && usr.Password == this.Password && usr.Email == this.Email)
                return true;
            else return false;
        }
        /// <summary>
        /// Verifies this user instance by data specified.
        /// </summary>
        /// <param name="Username">Specifies username for verification.</param>
        /// <param name="Password">Specifies password for verification.</param>
        /// <returns>True, if was verification successful, or false if it wasn't.</returns>
        public new bool VerifyUser(string Username, string Password)
        {
            if (Username == this.UserName && Password == this.Password)
                return true;
            else return false;
        }
        /// <summary>
        /// Overrides object.ToString() method for user friendly output.
        /// </summary>
        /// <returns>String with user friendly output.</returns>
        public override string ToString()
        {
            return String.Format("Username: {0}\r\nPassword: {1}\r\nEmail: {2}\r\nDescription: {3}\r\nRegister Date: {4}\r\nLast Login Date: {5}\r\nAge: {6}", 
                this.UserName, this.Password, this.Email, this.Description, this.RegisterDate.ToString(), this.LastLoginDate.ToString(), this.Age.ToString());
        }
    }
}